#include "QFntLibrary.h"

QFntLibrary::QFntLibrary(QString strFileName) : QLibrary(strFileName)
{
#ifdef WIN32
	m_hModalHandle = NULL;
#endif
}
QFntLibrary::QFntLibrary(QObject* parent) : QLibrary(parent)
{
}
QFntLibrary::~QFntLibrary()
{
	unload();
}
void QFntLibrary::setFileName(const QString &fileName)
{
	QLibrary::setFileName(fileName);
}
QString QFntLibrary::fileName() const
{
	return QLibrary::fileName();
}
void *QFntLibrary::resolve(const char *symbol)
{
#ifdef WIN32
	if (m_hModalHandle)
	{
		return GetProcAddress(m_hModalHandle, symbol);
	}
#endif
	return (void*)QLibrary::resolve(symbol);
}
bool QFntLibrary::load()
{
#ifdef WIN32
	QString strFilePath = fileName();
	strFilePath.replace("/","\\");
		m_hModalHandle = LoadLibraryEx(strFilePath.toStdString().c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
	if (m_hModalHandle == NULL)
	{
		strFilePath.append(".dll");
		m_hModalHandle = LoadLibraryEx(strFilePath.toStdString().c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
	}
	if (m_hModalHandle)
		return true;
#endif
	bool blret = QLibrary::load();
	return blret;
}
bool QFntLibrary::unload()
{
#ifdef WIN32
	if (m_hModalHandle)
	{
		FreeLibrary(m_hModalHandle);
		m_hModalHandle = NULL;
	}
#endif
	return QLibrary::unload();
}
bool QFntLibrary::isLoaded() const
{
#ifdef WIN32
	if (m_hModalHandle)
	{
		return true;
	}
#endif
	return QLibrary::isLoaded();
}
QString QFntLibrary::errorString() const
{
	return QLibrary::errorString();
}
